/*
 * @lc app=leetcode.cn id=383 lang=javascript
 *
 * [383] 赎金信
 */

// @lc code=start
/**
 * @param {string} ransomNote
 * @param {string} magazine
 * @return {boolean}
 */
var canConstruct = function (ransomNote, magazine) {
  const map = new Map();
  for (const ch of magazine) {
    map.set(ch, (map.get(ch) || 0) + 1);
  }
  for (const ch of ransomNote) {
    let val = map.get(ch);
    if (val) {
      if (val - 1 < 0) return false;
      map.set(ch, val - 1);
    } else {
      return false;
    }
  }
  return true;
};
// @lc code=end
